package com.example.mybroadcast;

import androidx.appcompat.app.AppCompatActivity;

import android.content.ComponentName;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

public class MainActivity extends AppCompatActivity {
    MyBroadcastReceiver myBroadcastReceiver;
    MyBroadcastReceiver1 myBroadcastReceiver1;
    MyBroadcastReceiver2 myBroadcastReceiver2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("Three_Broadcast");

        IntentFilter intentFilter1 = new IntentFilter();
        intentFilter1.addAction("Three_Broadcast1");

        myBroadcastReceiver = new MyBroadcastReceiver();
        intentFilter.setPriority(200);
        registerReceiver(myBroadcastReceiver,intentFilter);
        myBroadcastReceiver2 = new MyBroadcastReceiver2();
        intentFilter.setPriority(100);
        registerReceiver(myBroadcastReceiver2,intentFilter);

        myBroadcastReceiver1 = new MyBroadcastReceiver1();
        intentFilter.setPriority(300);
        registerReceiver(myBroadcastReceiver1,intentFilter);
        registerReceiver(myBroadcastReceiver1,intentFilter1);
    }
    public void sendThree(View view){
        Log.v("life","send");
        Intent intent = new Intent();
        // 定义广播的事件类型
        intent.putExtra("data1","数据1的值");
        intent.setAction("Three_Broadcast");
        sendOrderedBroadcast(intent,null);
    }
    public void sendThree1(View view){
        Log.v("life","send");
        Intent intent = new Intent();
        intent.putExtra("data2","数据2的值");
        // 定义广播的事件类型
        intent.setAction("Three_Broadcast1");
        sendOrderedBroadcast(intent,null);
    }
}

//        intent.setComponent(new ComponentName("com.example.mybroadcast","com.example.mybroadcast.MyBroadcastReceiver"));
// 发送广播